//
//  ControllerManager.m
//  Deepbreathing
//
//  Created by DreamHack on 15-8-13.
//  Copyright (c) 2015年 DreamHack. All rights reserved.
//

#import "ControllerManager.h"

@interface ControllerManager ()

@property (nonatomic, strong) UINavigationController * rootViewController;
@property (nonatomic, strong) DHTabViewController * mainTabController;
@property (nonatomic, strong) UINavigationController * loadViewController;

@end

@implementation ControllerManager

+ (ControllerManager *)sharedManager
{
    static ControllerManager * manager ;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[ControllerManager alloc] init];
    });
    return manager;
}

#pragma mark - getter
- (UINavigationController *)rootViewController
{
    if (!_rootViewController) {
        _rootViewController = [[UINavigationController alloc] initWithRootViewController:self.mainTabController];
        _rootViewController.navigationBarHidden = YES;
    }
    return _rootViewController;
    
}

- (DHTabViewController *)mainTabController
{
    if (!_mainTabController) {
        
        // 这的数组写入3个页面类
        // 生成tabController所管理的controller数组
        NSArray * controllerClassNames = @[@"MLPartyListViewController",@"CYYSponsorPartyViewController",@"CYYSetViewController"];
        
        NSMutableArray * viewControllers = [NSMutableArray arrayWithCapacity:0];
        
        [controllerClassNames enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            
            Class class = NSClassFromString(obj);
            UIViewController * controller = [[class alloc] init];
            [viewControllers addObject:controller];
        }];
        
        // NSLOG_CLASSNAME;
        // NSLog(@"%@",viewControllers);
        
        // 生成tabController
        _mainTabController = ({
        
            DHTabViewController * controller = [[DHTabViewController alloc] initWithViewControllers:viewControllers];
            
            controller;
        });
    }
    return _mainTabController;
}

- (UINavigationController *)loadViewController{
    if (!_loadViewController) {
        _loadViewController = ({
            Class class = NSClassFromString(@"CYYLoadViewController");
            UIViewController * loadViewController = [[class alloc]init];
            UINavigationController * loadViewNavController = [[UINavigationController alloc]initWithRootViewController:loadViewController];
            loadViewNavController.navigationBarHidden = YES;
            loadViewNavController;
        });
    }
    return _loadViewController;
}


@end
